<template>
	<view>
		<view class="cu-form-group margin-top">
			<view class="title">用户名</view>
			<input v-model="formData.username" placeholder="请输入用户名" name="input"></input>
		</view>
		<view class="cu-form-group">
			<view class="title">密码</view>
			<input v-model="formData.password" placeholder="请输入密码" name="input2"></input>
		</view>
		<view class="padding flex flex-direction">
			<button class="cu-btn block bg-blue margin-tb-sm lg" @click="submit()">登录</button>
		</view>
	</view>
</template>

<script>
	// import uniForms from '../../components/uni-forms/uni-forms.vue'
	// import uniFormsItem from '../../components/uni-forms-item/uni-forms-item.vue'
	export default {
		// components: {
		// 	uniForms,
		// 	uniFormsItem
		// },
		data() {
			return {
				formData: {
					username: 'liuzhe',
					password: '123456'
				},
				name: ""
				// rules: {
				// 	// 对name字段进行必填验证
				// 	name: {
				// 		rules: [{
				// 				required: true,
				// 				errorMessage: '请输入用户名',
				// 			},
				// 			{
				// 				minLength: 2,
				// 				maxLength: 20,
				// 				errorMessage: '用户名长度在 {minLength} 到 {maxLength} 个字符',
				// 			}
				// 		]
				// 	},
				// 	// 对email字段进行必填验证
				// 	password: {
				// 		rules: [{
				// 				required: true,
				// 				errorMessage: '请输入密码',
				// 			},
				// 			{
				// 				minLength: 6,
				// 				maxLength: 20,
				// 				errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符',
				// 			}
				// 		]
				// 	}
				// }
			}
		},
		onLoad() {

		},
		methods: {
			submit() {
				console.log(this.formData)
				uni.request({
					url: 'http://localhost:8082/task_admin/student/login',
					data: {
						username: this.formData.username,
						password: this.formData.password
					},
					method:"POST",
					success: (res) => {
						console.log(res)
						if (res.data.code == 200) {
							uni.setStorageSync('stuId', res.data.data.id);
							uni.navigateTo({
								url: '/pages/student/index-stu?name=' + res.data.data.name
							});
						} else {
							// this.$notify({
							// 	message: '用户名或密码错误',
							// 	background: 'danger',
							// 	duration: 500
							// })
							uni.showToast({
								// title: '用户名或密码错误',
								title: '登录失败',
								duration: 2000
							});
						}
					}
				});
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
